/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util;


import java.sql.ResultSet;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author phat10130059
 */
public class DateUtil {

   

    public static String getDateTimeToString() {
        Date d1 = new Date();
        SimpleDateFormat simpDate = new SimpleDateFormat("yyyyMMddHHmmss");
//        String id = simpDate.format(start);
        return simpDate.format(d1);
    }

    public static String dateToString(Date date) {

        DateFormat df = new SimpleDateFormat("h:mm:ss a");

        String reportDate = df.format(date);

        return reportDate;
    }

    public static String getDateToString(Date date) {
        DateFormat df = new SimpleDateFormat("dd/MM/yyyy");

        String reportDate = df.format(date);

        return reportDate;
    }

    public static String getHoursToString(Date date) {
        DateFormat df = new SimpleDateFormat("HH:mm:ss");

        String hours = df.format(date);

        return hours;
    }

    public static Date stringToDate(String str) {
        Date date = new Date();

        try {
            DateFormat df = new SimpleDateFormat("h:mm:ss a");
            date = df.parse(str);


        } catch (ParseException ex) {
            ex.printStackTrace();
        }

        return date;
    }

    

    public static boolean checkTime(String startDate, String endDate) {
        try {
            Date dateNow = new Date();

            DateFormat df = new SimpleDateFormat("h:mm:ss a");

            Date start = df.parse(startDate);
            Date end = df.parse(endDate);


            Date now = df.parse(DateUtil.dateToString(dateNow));


            if (now.after(start) && now.before(end)) {
                return true;
            }

        } catch (Exception ex) {
            ex.printStackTrace();
        }

        return false;

    }

    public static boolean checkDate(String start, String end, String search) {

        Date dateStart;
        Date dateEnd;
        Date dateSearch;

        try {
            dateStart = new SimpleDateFormat("dd/MM/yyyy").parse(start);
            dateEnd = new SimpleDateFormat("dd/MM/yyyy").parse(end);
            dateSearch = new SimpleDateFormat("dd/MM/yyyy").parse(search);
        } catch (ParseException ex) {
            
            ex.printStackTrace();
            return false;
        }

        if ((dateSearch.before(dateEnd) && dateSearch.after(dateStart))
                || (dateSearch.equals(dateStart) && dateSearch.equals(dateEnd))
                || (dateSearch.equals(dateStart) && dateSearch.before(dateEnd))
                || (dateSearch.equals(dateEnd) && dateSearch.after(dateStart))) {
            return true;
        }
        return false;
    }

//    public static void main(String args[]) {
//        boolean checkDate = checkDate("30/06/2014", "01/07/2014", "30/06/2014");
//        System.out.println(checkDate);
//    }
}
